//
//  topViewController.m
//  项目一
//
//  Created by nick on 15/7/17.
//  Copyright (c) 2015年 nick. All rights reserved.
//

#import "topViewController.h"
#import "DataService.h"
#import "movieRank.h"
#import "topCell.h"
#define sheight [UIScreen mainScreen].bounds.size.height
#define swidth [UIScreen mainScreen].bounds.size.width
#define sNavHeight 64
#define sTabBarHeight 49
@interface topViewController (){
    NSMutableArray *modalArray;
}

@end

@implementation topViewController
- (void)_createCollectionview{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((swidth-40)/3, (swidth-40)/3*1.5);
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
   // NSLog(@"%f,%f",(swidth-40)/3,(swidth-40)/3*1.5);
    UICollectionView *cv = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    cv.delegate = self;
    cv.dataSource = self;
    [self.view addSubview:cv];
    [cv registerNib:[UINib nibWithNibName:@"topCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cell"];
    
}
#pragma mark - collectionDatasourceAndDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return modalArray.count;
}
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    topCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.modal = modalArray[indexPath.row];
    return cell;
}
#pragma mark - dataLoad
- (void)dataLoad{
    modalArray = [NSMutableArray new];
    NSDictionary *dic = [DataService setDataWithJason:@"top250"];
    NSArray *subjects = [dic objectForKey:@"subjects"];
    for (NSDictionary *dic1 in subjects) {
        movieRank *top250modal = [[movieRank alloc]init];
        [top250modal setValuesForKeysWithDictionary:dic1];
        [modalArray addObject:top250modal];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataLoad];
    [self _createCollectionview];
    
    //[self _createCollectionview];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
